import Axios from "axios";
import {Toast} from 'mint-ui'
Axios.defaults.baseURL = 'https://www.aischolar.com/mobile';


//meetingcenter搜索和筛选请求
// let Request = function({url='',type='get',val={}}){
//     return new Promise((resolve,reject)=>{
//         if(!url){reject('请求的目标地址不存在')}
//         let result = Axios({
//             method: type,
//             url,
//             params:val
//         })
//         resolve(result)
//     })
// }

//meetingcenter搜索和筛选请求
let RequestPost = function({url='',type='post',data}){
    return new Promise((resolve,reject)=>{
        if(!url){reject('非法请求地址')}
        let result = Axios({
            method: type,
            url,
            data,
        })
        resolve(result)
    })
}

let RequestGet = function({url='',val={}}){
    return new Promise((resolve,reject)=>{
        if(!url){reject('非法请求地址')}
        let result = Axios({
            url,
            Header:{
                "Access-Control-Allow-Origin":"*",
                "Access-Control-Allow-Headers": "X-Requested-With,Content-Type",
                "Access-Control-Allow-Methods":"PUT,POST,GET,DELETE,OPTIONS",
            },
            params:val
        })
        resolve(result)
    })
}


let GetIndexBanner = ()=>{
    return new Promise((resolve,reject)=>{
        RequestGet({url:'/index/getBanner'})
            .then(res=>{
                if(res.data.code===0 || res.data.code==="0"){
                    reject("无数据")
                }else{
                    resolve(res.data.data)
                }
            })
            .catch(err=>{
                reject(err)
            })
    })
}

let GetSearch= val=>{
    return new Promise((resolve,reject)=>{
        RequestGet({url:'index/search',val})
            .then(res=>{
                if(res.data.code===0 || res.data.code==="0"){
                    // reject("无数据返回")
                    Toast(res.data.msg);
                }else{
                    resolve(res.data.data)
                }
            })
            .catch(err=>{
                reject(err)
            })
    })
}

let GetFillter = obj=>{
    return new Promise((resolve,reject)=>{
        RequestGet({url:'index/getMeetingList',val:obj})
            .then(res=>{
                if(res.data.code===0 || res.data.code==="0"){
                    reject(res.data.code);
                    Toast("无相关会议");
                }else{
                    resolve(res.data.data)
                }
            })
            .catch(err=>{
                reject(err)
            })
    })
}

let GetMeetingList = obj=>{
    return new Promise((resolve,reject)=>{
        RequestGet({url:'/index/getMeetingList',val:obj})
            .then(res=>{
                if(res.data.code===0 || res.data.code==="0"){
                    reject({code:0,msg:res.data.msg});
                }else{
                    resolve(res.data.data)
                }
            })
            .catch(err=>{
                console.log(err)
            })
    })
}

let GetCondition = ()=>{
    return new Promise((resolve,reject)=>{
        RequestGet({url:'index/Sidebar'})
            .then(res=>{
                if(res.data.code===0 || res.data.code==="0"){
                    reject("无数据")
                }else{
                    resolve(res.data.data)
                }
            })
            .catch(err=>{
                reject(err)
            })
    })
}

export {RequestGet,RequestPost,GetIndexBanner,GetSearch,GetFillter,GetMeetingList,GetCondition}
